package com.yhsimon.factory.simplefactory.pizzastore.order;

import com.yhsimon.factory.simplefactory.pizzastore.pizza.CheesePizza;
import com.yhsimon.factory.simplefactory.pizzastore.pizza.GreekPizza;
import com.yhsimon.factory.simplefactory.pizzastore.pizza.PepperPizza;
import com.yhsimon.factory.simplefactory.pizzastore.pizza.Pizza;

//简单工厂类
public class SimpleFactory {
    public Pizza createPizza(String orderType){
        Pizza pizza=null;
        System.out.println("使用简单工厂模式");
        if(orderType.equals("greek")){
            pizza=new GreekPizza();
            pizza.setName("GreekPizza");
        }else if(orderType.equals("cheese")){
            pizza=new CheesePizza();
            pizza.setName("CheesePizza");
        }else if(orderType.equals("pepper")){
            pizza=new PepperPizza();
            pizza.setName("PepperPizza");
        }
        return pizza;
    }

    //改进 设置为静态方法
    public static Pizza createPizza2(String orderType){
        Pizza pizza=null;
        System.out.println("使用简单工厂模式2");
        if(orderType.equals("greek")){
            pizza=new GreekPizza();
            pizza.setName("GreekPizza");
        }else if(orderType.equals("cheese")){
            pizza=new CheesePizza();
            pizza.setName("CheesePizza");
        }else if(orderType.equals("pepper")){
            pizza=new PepperPizza();
            pizza.setName("PepperPizza");
        }
        return pizza;
    }
}
